<%@ page language="java" import="java.sql.*"
import="java.util.List" 

import ="javax.ws.rs.core.MediaType" 
import ="javax.ws.rs.core.UriBuilder" 

import=" com.sun.jersey.api.client.*" 
import= "com.sun.jersey.api.client.config.ClientConfig" 
import= "com.sun.jersey.api.client.config.DefaultClientConfig" 

import ="classes.Market" 

 errorPage="" %>
 
<%
   
    
    String sUsername=request.getParameter("name");
    String sPassword=request.getParameter("pass");
    String message="User login successfully ";
    
    try{
    	ClientConfig config1 = new DefaultClientConfig();
	    Client client = Client.create(config1);
	    WebResource service = client.resource(UriBuilder.fromUri("http://localhost:8080/eKupovina").build());
	    List<Market> marketi= service.path("webservices").path("marketi").path("svi").accept(MediaType.APPLICATION_XML).get(new  GenericType<List<Market>>() {});
   int ok = 0;
	    for(int i=0; i<marketi.size(); i++) {
	    	if(sUsername.equals(marketi.get(i).getUsername()) && sPassword.equals(marketi.get(i).getPassword())) {
	    		 session.setAttribute("sIme",marketi.get(i).getUsername());
	    	      //session.setAttribute("sPrezime",sPrezime);
	    	      session.setAttribute("sKorisnickoIme",sUsername);
	    	      response.sendRedirect("pocetnaKorisnicka.jsp?error="+message);
	    	      ok=1;
	    	}
	    	
	    }
	    
	    
	    
	    if(ok==0)     {
    		
      message="No user or password matched" ;
      session.setAttribute("poruka",message );
      response.sendRedirect("pocetna.jsp?error="+message);
    }
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
    
    
    

%>